using UnityEngine;
using System.Collections;

public class Grab : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}


    void OnTriggerEnter(Collider other)
    {
        Debug.Log("Claw Collide");

        switch (transform.parent.GetComponent<PlayerController>().State)
        {
                
            case PlayerController.eStates.EXTENDING:
                {
                    // If we're landing on something we can't pick up, immediately retract
                    if (other.gameObject.GetComponent<Carryable>() == null)
                    {
                        Debug.Log("Can't pick up " + other.gameObject.name + ": retracting");
                        transform.parent.GetComponent<PlayerController>().State = PlayerController.eStates.RETRACTING;
                        
                    }
                    else
                    {
                        // is it grounded?
                        if (!other.gameObject.GetComponent<Carryable>().cooldown())
                        {

                            transform.parent.GetComponent<PlayerController>().heldObject = other.gameObject;
                            Debug.Log("Picking up " + transform.parent.GetComponent<PlayerController>().heldObject.name);
                            other.gameObject.transform.parent = transform;
                        }
                    }

                }
                break;

        };

    }

}
